const db = wx.cloud.database()
const getcardsCollection = db.collection('getcards')
const getStuCollection = db.collection('getStu')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    page:0,
    show: false,
    searchStuState: false,
    searchIDState: false,
    searchBankState: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  // onLoad: function (options) {
  //   getcardsCollection.where({
  //     state: false // 填入当前用户 openid
  //   }).get().then(res => {
  //     console.log(res.data)
  //     this.setData({
  //       products: res.data
  //     })
  //   })
  // },

  onLoad: function (options) {
    getcardsCollection.where({
      state: false // 填入当前用户 openid
    }).get().then(res => {
      console.log(res.data)
      this.setData({
        products: res.data
      })
    }).then(res => {
      getStuCollection.where({
        state: false
      }).get().then(res => {
        console.log(res.data)
        this.setData({
          getStu:res.data
        })
      })
    })
  },

  onPullDownRefresh: function () {
    getcardsCollection.where({
      state: false // 填入当前用户 openid
    }).get().then(res => {
      wx.stopPullDownRefresh()
      this.setData({
        products: res.data
      })
    })
  },

  onReachBottom: function(){
    console.log("触底啦")
    let page = this.data.page + 20;
    getcardsCollection.where({
      state: false // 填入当前用户 openid
    }).skip(page).get().then(res => {
      let new_data = res.data
      let old_data = this.data.products
      this.setData({
        products: old_data.concat(new_data),
        page: page
      })
    })
  },

  add:function(event){
    wx.navigateTo({
      url: 'loseCard/add/add',
    })
  },

  showstudent:function(event){
    this.setData({
      show:true,
      currentstudent: event.target.dataset.detail,
      currentcategoty:1
    })
  },

  showidentity: function (event) {
    this.setData({
      show: true,
      currentidentity: event.target.dataset.detail,
      currentcategoty: 2
    })
  },

  showbank: function (event) {
    this.setData({
      show: true,
      currentbank: event.target.dataset.detail,
      currentcategoty: 3
    })
  },

  onSearchStu: function(event){
    this.setData({
      searchStuState:true,
      searchStu:event.detail
    })
  },

  onCancelStu: function(event){
    this.setData({
      searchStuState: false
    })
  },


  onSearchID:function(event){
   this.setData({
     searchIDState:true,
     searchID: event.detail,
   })
  },

  onCancelID: function(evnet){
    this.setData({
      searchIDState: false
    })
  },

  onSearchBank: function(event){
    this.setData({
      searchBankState:true,
      searchBank: event.detail,
    })
  },

  onCancelBank: function(event){
    this.setData({
      searchBankState: false
    })
  }

})